package com.sibrary.booxoo;

import com.sibrary.utils.Constants;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.preference.Preference.OnPreferenceClickListener;
import android.widget.Toast;

public class BooxooSettingsPreferenceActivity extends PreferenceActivity {

//	private SharedPreferences mSharedPreferences;

	private Preference mHomePagePreference;
	private CheckBoxPreference mEnableJavaScriptCheckBoxPreference;
	private CheckBoxPreference mEnableLoadImageCheckBoxPreference;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.booxoo_settings_preferences);

//		mSharedPreferences = PreferenceManager
//				.getDefaultSharedPreferences(this);

		mHomePagePreference = (Preference) getPreferenceManager()
				.findPreference(Constants.PREFERENCE_KEY_HOMEPAGE);
		mHomePagePreference
				.setOnPreferenceClickListener(new OnPreferenceClickListener() {
					@Override
					public boolean onPreferenceClick(Preference preference) {
						openSetHomepageActivity();
						return true;
					}
				});

//		Boolean mEnableJavaScript = mSharedPreferences.getBoolean(
//				Constants.PREFERENCE_KEY_ENABLE_JAVASCRIPT, false);
//
//		mEnableJavaScriptCheckBoxPreference = (CheckBoxPreference) getPreferenceManager()
//				.findPreference(Constants.PREFERENCE_KEY_ENABLE_JAVASCRIPT);
//		mEnableJavaScriptCheckBoxPreference.setChecked(mEnableJavaScript);
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
			Preference preference) {
		// boolean flag = mSharedPreferences
		// .getBoolean(preference.getKey(), false);
		//
		// if (flag)
		// Toast.makeText(this, "true", Toast.LENGTH_LONG).show();
		// else
		// Toast.makeText(this, "false", Toast.LENGTH_LONG).show();

		return false;
	}

	/**
	 * 打开设置主页的窗口
	 */
	private void openSetHomepageActivity() {
		Intent i = new Intent(this, BooxooHomePageActivity.class);
		startActivity(i);
	}

}
